package cn.cs.service.impl;

import cn.cs.client.RepairComplaintClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.RepairComplaint;
import cn.cs.pojo.RepairComplaintNode;
import cn.cs.service.RepairComplaintService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class RepairComplaintServiceImpl implements RepairComplaintService {

    @Resource
    private RepairComplaintClient repairComplaintClient;

    public RepairComplaint getRepairComplaintById(String id) throws Exception {
        return repairComplaintClient.getRepairComplaintById(id);
    }

    public List<RepairComplaint> getRepairComplaintListByMap(Map<String, Object> param) throws Exception {
        return repairComplaintClient.getRepairComplaintListByMap(param);
    }

    public Integer getRepairComplaintCountByMap(Map<String, Object> param) throws Exception {
        return repairComplaintClient.getRepairComplaintCountByMap(param);
    }

    public Integer addRepairComplaint(RepairComplaint repairComplaint) throws Exception {
        return repairComplaintClient.addRepairComplaint(repairComplaint);
    }

    public Integer modifyRepairComplaint(RepairComplaint repairComplaint) throws Exception {
        return repairComplaintClient.modifyRepairComplaint(repairComplaint);
    }

    public Integer deleteRepairComplaintById(String id) throws Exception {
        return repairComplaintClient.deleteRepairComplaintById(id);
    }

    public Page<RepairComplaint> queryRepairComplaintPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = repairComplaintClient.getRepairComplaintCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<RepairComplaint> repairComplaintList = repairComplaintClient.getRepairComplaintListByMap(param);
        page.setRows(repairComplaintList);
        return page;
    }

    public Map<String, Object> getPersonByCode(String code) throws Exception {
        return repairComplaintClient.getPersonByCode(code);
    }

    public Integer addRepairComplaintNode(RepairComplaintNode repairComplaint) throws Exception {
        return repairComplaintClient.addRepairComplaintNode(repairComplaint);
    }

    public Page<RepairComplaintNode> queryRepairComplaintNodePageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize)throws Exception{
        Integer total = repairComplaintClient.getRepairComplaintNodeCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<RepairComplaintNode> repairComplaintNodeList = repairComplaintClient.getRepairComplaintNodeListByMap(param);
        page.setRows(repairComplaintNodeList);
        return page;
    }

    public List<RepairComplaintNode> getRepairComplaintNodeListByMap(Map<String, Object> param) throws Exception {
        return repairComplaintClient.getRepairComplaintNodeListByMap(param);
    }
}
